(function(){
    "use strict";
    var pipeController=function ($scope,$http,$modal){

        $scope.vm = {
            "config" : true,
            "configCopy" : 'create',
            "workflow" : {
                "triggers" : true,
                "tasks" : [
                    {
                        "id" : 2011,
                        "selected" : false,
                        "isClick" : false,
                        "selectedItemId" : 0,
                        "isSelectShow" : true
                    }

                ]

            }
        };

        //删除pipe中某个task
        $scope.pipeLineRemove = function(index){
            if($scope.vm.workflow.tasks.length>1){
                $scope.vm.workflow.tasks.splice(index,1);
                //右边配置页面显示下一个task的配置项
                $scope.selectedItemId = $scope.vm.workflow.tasks[index].selectedItemId;
            }else if($scope.vm.workflow.tasks.length == 1){
                $scope.vm.workflow.tasks.splice(index,1);
                //右边配置页面显示下一个task的配置项
                $scope.selectedItemId = {};
            }
        };

        //单击某个task显示task下拉框进行任务选择
        $scope.configTask = function(taskItem){
            //切换成task下拉选择框
            taskItem.isClick = true;
            taskItem.selected = true;
            if(taskItem.selectedItemId == 0){
                //新增加一个task
                var task = {
                    "id" : taskItem.id+1,
                    "isClick" : false,
                    "selectedItemId" : 0,
                    "isSelectShow" : true
                };
                $scope.vm.workflow.tasks.push(task);
//                console.log("id:"+(task.id));
            }
        };

        //单击某个task进行任务配置页的显示
        $scope.configShow = function(taskItem){
            if(taskItem.selectedItemId != 0){
                console.log("$scope.selectedItemId:"+taskItem.selectedItemId);
                $scope.selectedItemId = taskItem.selectedItemId;
            }
        };

        //将具体的任务类型固定化
        $scope.taskStyle = [
            {
                "id" : 1,
                "name" : "项目启动"
            },
            {
                "id" : 2,
                "name" : "研发过程"
            },
            {
                "id" : 3,
                "name" : "在线测试"
            },
            {
                "id" : 4,
                "name" : "上线交付"
            },
            {
                "id" : 5,
                "name" : "验收环节"
            }
        ];

        //当前需显示的任务配置页
        $scope.selectedItemId = {};
        //选择任务类型的方法
        $scope.TSChoose = function(taskItem,selectedTS){
            //隐藏选择框，显示任务名
            taskItem.isSelectShow = false;

            if(selectedTS != undefined){
                taskItem.selectedItemId = selectedTS.id;
            }
        };






    };

    angular.module("cicd.pipeline",[])
            .controller("PipeController",["$scope","$http","$modal",pipeController])

})();